﻿//公共方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SN.Data;
using System.Data;
using SN.Models;
namespace SN.Services
{
    public class SNService
    {

        public static T_User User;//

        public static string GetLSBH<T>() where T : SN.Data.Entity
        {
            string Msg = string.Empty;
            Type t = typeof(T);
            string tableName = t.FullName.Substring(t.FullName.LastIndexOf('.') + 1); //取实体表名
            SN.Models.T_CONF pConf = null;
            pConf = DBUtility.DB.Single<SN.Models.T_CONF>(T_CONF._.CONF_KEY == tableName);
            if (pConf == null)
            {
                pConf = new T_CONF();

                pConf.CONF_KEY = tableName;
                pConf.CONF_VALUE = "1";
                pConf.CONF_NOTE = tableName;

                pConf.Detach();
            }
            else
            {
                pConf.CONF_VALUE = Convert.ToString(Convert.ToInt16(pConf.CONF_VALUE) + 1);
                pConf.Attach();
            }
            DBUtility.DB.Save<T_CONF>(pConf);
            return pConf.CONF_VALUE.PadLeft(6, '0');//长度为6位，能满足需求
        }

        #region Show Error
        public static void ShowError(string msg)
        {
            MessageBox.Show(msg);
        }
        #endregion

        #region Hourglass
        public static void Hourglass(bool Show)
        {
            if (Show == true)
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
            }
            else
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
            }
            return;
        }
        #endregion

    }



}
